const NOTIFICATIONS_INTERVAL = 5;

var feedUrl2contentLength = {};

var notification = webkitNotifications.createNotification(
    'img/gba48x48.jpg',  // icon url - can be relative
    'OBAVIJEST!',  // notification title
    'Imas novu poruku, notifikaciju, temu ili vijest...'  // notification body text
);

function runNotificationsTimer(url, title, icon, text) {
    setInterval(function(){
        var xhr = new XMLHttpRequest();
        xhr.open("GET", "http://www.gamers.ba/q/pvtmsg/all", true);
		    xhr.send();
        xhr.onload = function(e) {

            var oldContentLength = feedUrl2contentLength[url];

            if (!oldContentLength || oldContentLength != e.target.responseText.length) {
                notification.show();

                feedUrl2contentLength[url] = e.target.responseText.length;
            }

        };
        xhr.send(null);
    }, 5);
}

    runNotificationsTimer('http://gamers.ba/', 'GAMERS.ba Tools by Brix', 'img/gba48x48.jpg', 'Imaš novu poruku!');
    runNotificationsTimer('http://gamers.ba/q/pvtmsg/all', 'GAMERS.ba Tools by Brix', 'img/gba48x48.jpg', 'Dobio si poruku, notifikaciju ili je napisana nova vijest ili tema.');
document.addEventListener('DOMContentLoaded', function () {
    
});